package com.yc.exam.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.exam.entity.ExamTopic;
import com.yc.exam.entity.Topic;
import com.yc.exam.mapper.TopicMapper;
import com.yc.exam.service.IExamTopicService;
import com.yc.exam.service.ITopicService;
import com.yc.exam.vo.TopicVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 服务实现类
 *
 * @author exam
 * @since 2022-03-23
 */
@Service
public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements ITopicService {
  @Autowired private IExamTopicService examTopicService;

  @Autowired private TopicMapper topicMapper;



  @Override
  public List<Topic> getTopicListByExamId(Long examId) {
    final List<Long> topicIds =
        examTopicService
            .list(new LambdaQueryWrapper<ExamTopic>().eq(ExamTopic::getExamId, examId))
            .stream()
            .map(ExamTopic::getTopicId)
            .collect(Collectors.toList());
    if (topicIds.isEmpty()) {
      return new ArrayList<>();
    }
    return listByIds(topicIds);
  }

  @Override
  public Page<TopicVo> loadVoPage(Page<Topic> examPage, TopicVo topic) {
    return  topicMapper.loadPage(examPage,topic);
  }
}
